<template>
  <div class="index" v-cloak>
    <div class="header acea-row row-center-wrapper">
      <div class="logo"><img :src="logoUrl" /></div>
      <router-link :to="'/search'" class="search acea-row row-middle">
        <span class="iconfont icon-xiazai5"></span>搜索商品
      </router-link>
    </div>
    <div class="slider-banner banner">
      <swiper :options="swiperOption" v-if="banner.length > 0">
        <swiper-slide v-for="(item, index) in banner" :key="index">
          <router-link
            :to="item.wap_url ? item.wap_url : ''"
            class="search acea-row row-middle"
          >
            <img :src="item.pic" />
          </router-link>
        </swiper-slide>
        <div class="swiper-pagination paginationBanner" slot="pagination"></div>
      </swiper>
    </div>
    <div class="nav acea-row">
      <router-link
        :to="item.wap_url ? item.wap_url : ''"
        class="item"
        v-for="(item, index) in menus"
        :key="index"
      >
        <div class="pictrue"><img :src="item.pic" /></div>
        <div>{{ item.name }}</div>
      </router-link>
    </div>
    <div class="promotion-area-title">
      <img src="../../assets/images/promotion-area.png" alt="" />
    </div>
    <div class="promotion-area">
      <div class="seckill">
        <div class="seckill-title"></div>
        <div class="seckill-subtitle">民宿家居火热销售</div>
        <div class="time">
          <span class="timeTxt"></span>
          <span class="styleAll">00</span>
          <span class="timeTxt"> : </span>
          <span class="styleAll">00</span>
          <span class="timeTxt"> : </span>
          <span class="styleAll">00</span>
          <span class="timeTxt"></span>
        </div>
      </div>
      <div class="assemble">
        <div class="assemble-title">一起来拼团</div>
        <div class="assemble-subtitle">优惠多多</div>
        <img src="../../assets/images/assemble-bg1.png" />
      </div>
    </div>
    <div class="hotList" v-if="benefit.length > 0">
      <div data-v-76131e3e="" class="publicTitle acea-row row-center-wrapper">
        <img data-v-76131e3e="" src="../../assets/images/remenbangdan.png" />
        <a data-v-76131e3e="" href="/hot_new_goods/2" class="more">更多 &gt;</a>
      </div>
      <div class="list acea-row">
        <a
          href="/detail/54"
          v-for="(item, index) in benefit"
          :key="index"
          class="item"
        >
          <div data-v-76131e3e="" class="pictrue">
            <img :src="item.image" />
          </div>
          <div class="text">
            <div class="name line1">{{ item.store_name }}</div>
            <div class="money font-color-red">
              ¥<span class="num">{{ item.price }}</span>
            </div>
          </div>
        </a>
      </div>
    </div>
    <div class="promotion" v-if="benefit.length > 0">
      <div class="publicTitle acea-row row-center-wrapper">
        <img src="../../assets/images/shangpincuxiao.png" />
        <a href="/promotion" class="more">更多 &gt;</a>
      </div>
      <div class="publicList acea-row row-between-wrapper">
        <a
          href="/detail/54"
          v-for="(item, index) in benefit"
          :key="index"
          class="item"
        >
          <div class="pictrue">
            <img :src="item.image" />
          </div>
          <div class="text">
            <div class="name line1">{{ item.store_name }}</div>
            <div class="acea-row row-between-wrapper">
              <div>
                <div class="money font-color-red">
                  ¥<span class="num">{{ item.price }}</span>
                  <span class="label"></span>
                </div>
                <div class="ot-money">{{ item.ot_price }}</div>
              </div>
              <div class="cart acea-row row-center-wrapper"></div>
            </div>
          </div>
        </a>
      </div>
    </div>
    <div class="recommend" v-if="benefit.length > 0">
      <div class="title">
        <img src="../../assets/images/hailiangjinping.png" />
      </div>
      <div class="publicList acea-row row-between-wrapper">
        <a
          href="/detail/54"
          v-for="(item, index) in benefit"
          :key="index"
          class="item"
        >
          <div class="pictrue">
            <img :src="item.image" />
          </div>
          <div class="text">
            <div class="name line1">{{ item.store_name }}</div>
            <div class="acea-row row-between-wrapper">
              <div>
                <div class="money font-color-red">
                  ¥<span class="num">{{ item.price }}</span>
                  <span class="label"></span>
                </div>
                <div class="ot-money">¥{{ item.ot_price }}</div>
              </div>
              <div class="cart acea-row row-center-wrapper">
                <span class="iconfont icon-mzshopping"></span>
              </div>
            </div>
          </div>
        </a>
      </div>
    </div>
    <Coupon-window
      :coupon-list="couponList"
      v-if="showCoupon"
      @checked="couponClose"
      @close="couponClose"
    ></Coupon-window>
    <div style="height:1.2rem;"></div>
  </div>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
import "@assets/css/swiper.min.css";
import GoodList from "@components/GoodList";
import PromotionGood from "@components/PromotionGood";
import CouponWindow from "@components/CouponWindow";
import { getHomeData, getShare } from "@api/public";
import cookie from "@utils/store/cookie";
import { openShareAll } from "@libs/wechat";
import { isWeixin } from "@utils/index";

const HAS_COUPON_WINDOW = "has_coupon_window";

export default {
  name: "Index",
  components: {
    swiper,
    swiperSlide,
    GoodList,
    PromotionGood,
    CouponWindow
  },
  props: {},
  data: function() {
    return {
      showCoupon: false,
      logoUrl:
        "http://demo3.crmeb.net/uploads/attach/2019/11/20191126/84f2d5bc7867646fdd671380e2b35981.png",
      banner: [],
      menus: [],
      roll: [],
      activity: [],
      activityOne: {},
      info: {
        fastList: [],
        bastBanner: [],
        firstList: [],
        bastList: []
      },
      likeInfo: [],
      lovely: [],
      benefit: [],
      couponList: [],
      swiperOption: {
        pagination: {
          el: ".paginationBanner",
          clickable: true
        },
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperRoll: {
        direction: "vertical",
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperScroll: {
        freeMode: true,
        freeModeMomentum: false,
        slidesPerView: "auto",
        observer: true,
        observeParents: true
      },
      swiperBoutique: {
        pagination: {
          el: ".paginationBoutique",
          clickable: true
        },
        autoplay: {
          disableOnInteraction: false,
          delay: 2000
        },
        loop: true,
        speed: 1000,
        observer: true,
        observeParents: true
      },
      swiperProducts: {
        freeMode: true,
        freeModeMomentum: false,
        slidesPerView: "auto",
        observer: true,
        observeParents: true
      }
    };
  },
  mounted: function() {
    let that = this;
    getHomeData().then(res => {
      that.logoUrl = res.data.logoUrl;
      that.$set(that, "banner", res.data.banner);
      that.$set(that, "menus", res.data.menus);
      that.$set(that, "roll", res.data.roll);
      that.$set(that, "activity", res.data.activity);
      if (res.data.activity.length) {
        var activityOne = res.data.activity.shift();
        that.$set(that, "activityOne", activityOne);
      }
      that.$set(that, "info", res.data.info);
      that.$set(that, "likeInfo", res.data.likeInfo);
      that.$set(
        that,
        "lovely",
        res.data.lovely.length ? res.data.lovely[0] : {}
      );
      that.$set(that, "benefit", res.data.benefit);
      that.$set(that, "couponList", res.data.couponList);
      that.setOpenShare();
      this.showCoupon =
        !cookie.has(HAS_COUPON_WINDOW) &&
        res.data.couponList.some(coupon => coupon.is_use);
    });
  },
  methods: {
    couponClose() {
      cookie.set(HAS_COUPON_WINDOW, 1);
    },
    setOpenShare: function() {
      if (isWeixin()) {
        getShare().then(res => {
          var data = res.data.data;
          var configAppMessage = {
            desc: data.synopsis,
            title: data.title,
            link: location.href,
            imgUrl: data.img
          };
          openShareAll(configAppMessage);
        });
      }
    }
  }
};
</script>
<style scoped>
.index {
  background-color: #fff;
}
</style>
